<?php
namespace App\Http\Controllers\desktop\publics;

use App\Models\Section;
use App\Models\Book;

class SectionController extends BaseController {
	
	public function show($bookId, $order) {
		$book = Book::find($bookId);
		if(is_null($book)) {
			return redirect('/404');
		}
		$book->clicks = ($book->clicks + 1);
		$book->save();
		$section = Section::where('book_id', $book->id)
				->where('order', (int)$order)->first();
		if(is_null($section)) {
			return redirect('/404');
		}
		$category = $book->category;
		session([$book->id => (int)$section->order]);
		return view('desktop.publics.section', compact('section', 'book', 'category'));
	} 
}
